import WeiQiImpl, { Options } from "./WeiQiImpl"
import { WeiQi, Chess, ErrorMsg, ChessType } from './WeiQi'
import Music from './Music'

export const WeiQiMusic = Music

export function createWeiQi(dom: HTMLDivElement, options: Options | null): WeiQi {
  const weiqi = new WeiQiImpl(dom, options)

  return {
    set boardSize(size: number) {
      weiqi.boardSize = size
    },
    get boardSize() {
      return weiqi.boardSize
    },
    set chessType(chessType: ChessType) {
      weiqi.chessType = chessType
    },
    get chessType() {
      return weiqi.chessType
    },
    changeRoadNum: weiqi.changeRoadNum.bind(weiqi),
    clickBoard: weiqi.clickBoard.bind(weiqi),
    reset: weiqi.reset.bind(weiqi),
    getChessBoard: weiqi.getChessBoard.bind(weiqi),
    getStepCount: weiqi.getStepCount.bind(weiqi),
    getSteps: weiqi.getSteps.bind(weiqi),
    initSize: weiqi.initSize.bind(weiqi),
    set onBeforePut(callBack: (chess: Chess) => boolean) {
      weiqi.onBeforePut = callBack
    },
    set onError(callBack: (err: ErrorMsg) => void) {
      weiqi.onError = callBack
    },
    set onAfterPut(callBack: (chess: Chess) => void) {
      weiqi.onAfterPut = callBack
    },
    readStep: weiqi.readStep.bind(weiqi),
    backStep: weiqi.backStep.bind(weiqi),
    useMusic: weiqi.useMusic.bind(weiqi)
  }
}